package com.origin.src.dep;

import com.origin.src.ApplicationTool;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.*;
import org.springframework.stereotype.Component;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Configuration
@DepApplicationContext.ImportTest
@PropertySource("/application.properties")
public class DepApplicationContext {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(DepApplicationContext.class);
        ApplicationTool.printBean(applicationContext);
    }

    @Bean
    public static DepBeanC depBeanC(@Value("a") String a, @Value("b") String b) {
        return new DepBeanC();
    }


    @Configuration
    @Import(DepA.class)
    class DI {

    }

    public static class DepBeanC {


    }

    @Component
    public static class DepBeanD implements FactoryBean<DepBeanE> {

        public DepBeanD(@Value("a") String a, @Value("b") String b) {

        }


        @Override
        public DepBeanE getObject() throws Exception {
            return new DepBeanE();
        }

        @Override
        public Class<?> getObjectType() {
            return DepBeanE.class;
        }
    }

    public static class DepBeanE {


    }

    @Target(ElementType.TYPE)
    @Retention(RetentionPolicy.RUNTIME)
    @Import(DepApplicationContext.DI.class)
    public @interface ImportTest {
    }


}
